package com.dayuanit.dy16.spider.util;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;

public class SleepUtils {

    private static int[] times = {200, 300, 400, 500, 600, 700, 400, 300,800, 900, 1000, 1100,1500, 1600, 1800, 1900};

    public static void sleep() {
        int index = ThreadLocalRandom.current().nextInt(times.length);
        try {
            Thread.sleep(times[index]);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
//        for (int i=0; i<10; i++) {
//            System.out.println(sleep());
//        }


        //根据题意，换个逻辑：取出小于5的前三个数字  取出大于5的后三个数字
        List<Integer> nums = Arrays.asList(5, 6, 1, 7, 9, 2, 0, 3, 8, 1, 7);

        //排序
        nums.sort((a, b) -> a.compareTo(b));
        nums.forEach(System.out::print);

        System.out.println();

        //大于5的数字 取三个
        List<Integer> more5 = nums.stream().filter(el -> el.intValue() > 5).limit(3).collect(Collectors.toList());
        more5.forEach(System.out::print);

        System.out.println();

        //小于5的数字 取三个
        List<Integer> less5 = nums.stream().sorted(Comparator.reverseOrder()).filter(el -> el.intValue() < 5).limit(3).collect(Collectors.toList());
        less5.forEach(System.out::print);
    }
}
